<?php
interface OfferConst {
	/**
	 * 悬赏开始
	 */
	const OFFER_INIT="1";
	/**
	 * 悬赏结贴
	 */
	const OFFER_KONT="2";
	/**
	 * 悬赏过期
	 */
	const OFFER_TIMEOUT="3";

}

if(!defined('IN_JISHIGOU')) {
	exit('invalid request');
}

class ModuleObject extends MasterObject {
	private $offerList;
	private $count;
	private $Moffer;
	private $wherePart;

	function ModuleObject($config) {
		$this->Moffer = M('offer');
		$this->MasterObject($config);
		$this->Execute();
	}

	function Execute(){
		ob_start();
		if(!empty($this->Code)){
			$this->{$this->Code}();
		}else{
			$this->setting();
		}


		$body = ob_get_clean();
		$this->ShowBody($body);
	}

	function main(){
		$option = array();
		$option['page_url'] ='admin.php?mod=offer';
		$this->Title = '悬赏';
		include template('admin/offer/offer_mian');
	}
	function knot(){
		$option = array();
		$option['page_url'] ='admin.php?mod=offer';
		$this->Title = '悬赏';
		include template('admin/offer/offer_mian');
	}



	function setting(){
		$config = $this->Config;
		$checked['open'][$config['offer_open'] ? $config['offer_open'] : 0] = "checked";

		include template('admin/offer/offer_setting');
	}

	function dosetting(){
		$config = array();
		$config['offer_open'] = $this->Post['open'] ? $this->Post['open'] : 0;
		$config['offer_point_min'] = $this->Post['pMin'] ? $this->Post['pMin'] : 0;
		$config['offer_point_max'] = $this->Post['pMax'] ? $this->Post['pMax'] : 0;
		$config['offer_day_min'] = $this->Post['dMin'] ? $this->Post['dMin'] : 0;
		$config['offer_day_max'] = $this->Post['dMax'] ? $this->Post['dMax'] : 0;
		ConfigHandler::update($config);
		$this->Messager('操作成功了');
	}

	/**
	 * 结贴
	 */
	public function doknot(){
		$offerInfo=$this->Moffer;
		$offerInfo->create();
		$offerInfo->knotTime=time();
		$offerInfo->isAdmin=1;
		$offerInfo->status=OfferConst::OFFER_KONT;
		$offerInfo->save();
		$this->succ("操作成功");
	}

}

?>